package crafex.engine.system;

import java.util.HashMap;

public class Console {
	private static HashMap<String, Command> commands;
	
	public Console(){
		
	}
	
	public void addCommand(String caller, Command command){
		commands.put(caller, command);
	}
	
	public void removeCommand(String caller){
		commands.remove(caller);
	}
	
	public Command getCommand(String caller){
		return commands.get(caller);
	}
	
	public void setCommand(String caller, Command command){
		commands.put(caller, command);
	}
	
	/**
	 * runs the command the provided caller is assigned to
	 * @param caller the caller of the command 
	 */
	public void runCommand(String caller){
		getCommand(caller).run();
	}
	
	public void runCommand(String caller, Object[] args){
		getCommand(caller).run(args);
	}
	
	public static void runCommand(Command command){
		if(command != null){
			command.run();
		}
	}
	
	public static void runCommand(Command command, Object[] args){
		if(command != null){
			command.run(args);
		}
	}
}